-- apper_poisoned
-- created by panyl
-- 怪物出现时概率中毒

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 攻击时触发
    trigger = function(who, prop, arg)
        local grid = arg;

        -- 不是怪物
        if not grid:isMonster() then
            return false;
        end

        -- 概率没发生
        if DungeonM.getRandSeed("apper_poisoned") % 1000 >= prop[3] then
            return false;
        end

        local propId = PropM.getPropId("poisoned");

        -- 中毒威力
        local v;
        -- 伤害=魔力时
        if prop[2] == "magic" then
            local floor = DungeonM.currentLayer();
            local dungeonId = DungeonM.getDungeonId();
            if dungeonId == nil then
                dungeonId = ME.user.dbase:query("currentDungeon");
            end
            local layerFix = DungeonAreaM.query(dungeonId,"layer_fix");
            local magic = who:getMagic();
            v = math.modf(magic * 60000 / floor / (60 + layerFix))+1;
        else
            v = prop[2];
        end

        local effectRound = CombatM.getRound() + prop[4];
        local arr = { propId, 1, v, effectRound, };

        local condition = {
            ["prop"] = arr,
            ["end_round"] = effectRound,
        };
        -- 附加状态
        CombatStatusM.applyStatus(grid.monster, "poisoned", condition);

        return true;
    end,

    record = function(target, prop, path)
        return false;
    end
};
